# -*- coding: utf-8 -*-
filterhost = [];
import os
from util import httpheaders
filteroutpage = u"""
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>filterout,该页已被服务器端过滤掉 public wallproxy-fixed servers</title>
</style>
</head>
<body>
<p>您访问的网页被wallproxy-fixed公开服务端过滤掉</p>
<p>被过滤的原因可能有：</p>
<p>1.您所访问的视频网站太消耗网络流量资源,为了保障大多数用户的体验，只能过滤掉那些网站</p>
<p></p>
<p>以下是一些详细信息：</p>
%s
<p>You request url had been filter out!</p>
<p>This is a public wallproxy-fixed servers.</p>
<p>please vist <a href="http://you-proxy.googlecode.com/">you-proxy</a></p>
<p>
<a href="http://code.google.com/appengine/">
<img src="http://code.google.com/appengine/images/appengine-silver-120x30.gif" alt="Powered by Google App Engine" 
tyle="vertical-align: middle" /></a></p>
</body></html>
"""
def urlfilter(url):
  try:
    host = url.split('/')[2]
    if ('.'.join(host.split('.')[-2:]) in filterhost):
      return False
  except:
    return True;
  return True;

def showinfo(url):
  info =  "<p>you request url:  %s</p>" %url
  info += "<p>APPLICATION_ID:   %s</p>" %os.environ['APPLICATION_ID']
  info += "<p>REMOTE_ADDR:      %s</p>" %os.environ['REMOTE_ADDR']
  info += "<p>HTTP_USER_AGENT:  %s</p>" %os.environ['HTTP_USER_AGENT']
  info += "<p>PATH_INFO:        %s</p>" %os.environ['PATH_INFO']
  content = filteroutpage%(info)
  headers = httpheaders.HTTPHeaders({'Server':'WallProxy',
                'Content-Type':'text/html', 'Content-Length':len(content)})
  return (403,
          headers,
          content.encode('utf-8'),
           )
